package com.qijian.tool.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qijian.tool.domain.Msg;
import com.qijian.tool.domain.query.MsgQuery;
import com.qijian.tool.domain.vo.DictData;
import com.qijian.tool.domain.vo.MsgVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Set;

/**
 * 我的信息Mapper接口
 *
 * @author qijian
 * @date 2022-06-06
 */
public interface MsgMapper extends BaseMapper<Msg> {

    @Select("select count(0) from sys_msg WHERE create_time >= CURRENT_DATE ")
    int countCurrentDateWithDel();


    Page<MsgVo> selectVo(Page<MsgVo> page, @Param(Constants.WRAPPER) Wrapper<MsgQuery> queryWrapper);


    List<Msg> queryUserWxUserIds(@Param("userIds") Set<Long> userIds);


    @Select("select count(1) from sys_config sc where config_key ='wx:enableMsg'  and config_value ='Y' ")
    int enableWxFlag();

    @Select("select client_id from sys_user_extra where user_id = #{userId} and client_id is not null")
    String getClientIdByUserId(@Param("userId") Long userId);

    @Select("select " +
            "    client_id " +
            " from " +
            "    sys_user_extra a " +
            " inner join sys_msg  b on  a.user_id = b.user_id and b.is_del = 0 and b.version =#{version}  " +
            " where " +
            "   client_id is not null")
    List<String> getClientIdsByVersion(@Param("version") String version);

    @Select(" select  * from sys_dict_data  where dict_type = 'app_msg_push' and dict_value = #{dictValue} ")
    DictData getDataByDictKey(@Param("dictValue") String dictValue);

    Msg getFullById(@Param("msgId") Long msgId);
}
